<div class="col-lg-4">
	<div id="fileTreeView"></div>
</div>
<div class="col-lg-8">
	<table id="fileListTable" class="table table-striped table-hover">
		<thead>
			<tr>
				<th width="60">#</th>
				<th>名称</th>
				<th>类型</th>
				<th>大小</th>
				<th>操作</th>
			</tr>
		</thead>
	</table>
</div>
<script th:inline="javascript">
    /*<![CDATA[*/
    function deleteFile(obj) {
        var deleteUrl = /*[[@{/admin/m/base/template/deleteFile.gsp}]]*/'url';
        tg_dleteItem(deleteUrl + '?filePath=' + $(obj).attr('filePath'), function() {
            fileListTable.refresh();
        });
    }
    //表格
    var fileListTable;
    //表格列定义
    var columnDefs = [ {
        //第一列，用来拖拽
        "searchable" : false,
        "orderable" : false,
        "targets" : 0
    } ];
    var columns = [ {
        //第一列，用来拖拽
        "data" : null,
        "class" : "text-center"
    }, {
        "data" : "fileName",
        render : function(data, type, row, meta) {
            var fileClass = row.leaf ? 'fa fa-file-code-o text-warning' : 'fa fa-folder text-warning';
            var editUrlPre = /*[[@{/admin/m/base/template/editFile.gsp?filePath=}]]*/'url';
            if (!row.leaf) {
                return '<a onclick="refreshFileList(this)" leaf="' + row.leaf + '" parentPath="' + row.filePath + '"><i class="'+fileClass+'"></i> ' + data + '</a>';
            } else {
                return '<a href="' + (editUrlPre + row.filePath) + '" data-target="#templateWin" data-toggle="modal""><i class="'+fileClass+'"></i> ' + data + '</a>';
            }
        }
    }, {
        "data" : "format"
    }, {
        "data" : "fileLength",
        render : function(data, type, row, meta) {
            return TG_UTIL.fileSize(data);
        }
    }, {
        "data" : null, //最后一列，操作按钮
        "class" : "text-center",
        render : function(data, type, row, meta) {
            var result = '';
            //删除按钮
            result += ' <a href="#" type="button" onclick="deleteFile(this)" filePath="' + row.filePath + '" class="btn btn-danger btn-xs"><i class="fa fa-trash-o"></i></a>';
            return result;
        }
    } ];

    var parentPath = /*[[${result.codeNum}]]*/'';
    //ajax参数
    var ajaxDataParamFun = function(d) {
        d.parentPath = parentPath;
    };
    //表格setting
    var setting = {
        listUrl : /*[[@{/admin/m/base/template/getFilesByPath.gsp}]]*/'url',
        columnDefs : columnDefs, //表格列定义
        columns : columns, //表格列
        dataTableDiv : 'fileListTable', //表格
        ajaxDataParamFun : ajaxDataParamFun, //ajax参数
        pageable : false, //是否分页
        showIndexColumn : true, //是否显示第一列的索引列
        enabledChange : false
    };
    //创建表格
    fileListTable = new TG_Tabel.createNew(setting);
    //加载完成后执行
    $(function() {
        //表格初始化
        fileListTable.init();

        var url = /*[[@{/admin/m/base/template/getFileTree.gsp}]]*/'url';
        tg_simpleAjaxPost(url, {
            codeNum : /*[[${result.codeNum}]]*/''
        }, function(d) {
            var result = $.parseJSON(d);
            $('#fileTreeView').treeview({
                color : "#428bca",
                showBorder : false,
                nodeIcon : null,
                data : result.obj.nodes,
                onNodeSelected : function(event, folder) {
                    parentPath = folder.filePath;
                    fileListTable.refresh();
                }
            });
        });
    });

    function refreshFileList(obj) {
        if ($(obj).attr('leaf') == 'false') {
            parentPath = $(obj).attr('parentPath');
            fileListTable.refresh();
        }
    }

    /*]]>*/
</script>
